from django.shortcuts import render
from rest_framework.generics import CreateAPIView
from rest_framework.response import Response
from rest_framework.views import APIView
from .serializers import CreateUserSerializer
from .models import User
# Create your views here.


# 判断用户名存在
# get /username/

class UsernameView(APIView):
    def get(self, request, username):
        # 查询用户的数量
        count = User.objects.filter(username=username).count()
        data = {
            'username': username,
            'count': count
        }
        return Response(data)

class MobileView(APIView):
    def get(self, request, mobile):
        # 查询用户的数量
        count = User.objects.filter(mobile=mobile).count()
        databases = {
            'mobile': mobile,
            'count': count
        }
        return Response(databases)

# 注册接口
class UserView(CreateAPIView):
    serializer_class = CreateUserSerializer